<template>
  <!-- 岗位 表单页面 -->
  <div v-if="crud.status.cu > 0">
    <el-drawer
      :title="crud.status.title"
      :visible.sync="crud.status.cu > 0"
      direction="rtl"
      :before-close="crud.cancelCU"
      :wrapper-closable="false"
      size="400px"
    >
      <div class="leisure-drawer__content">
        <el-form
          ref="form"
          :model="form"
          :rules="rules"
          size="small"
          label-width="100px"
        >
          <el-form-item label="岗位名称" prop="name">
            <el-input v-model="form.name" placeholder="请输入岗位名称" clearable />
          </el-form-item>

          <el-form-item label="岗位编码" prop="code">
            <el-input v-model="form.code" placeholder="请输入岗位编码" clearable />
          </el-form-item>
          <!-- 自动转换depId 为depName -->
          <el-form-item label="所属组织" prop="depId">
            <dep-tree v-model="form.depId" :dep-input-change="depSearchInput" :load-on-mounted="true" />
          </el-form-item>
          <el-form-item
            label="排序"
            prop="paixu"
          >
            <el-input-number
              v-model.number="form.paixu"
              :min="0"
              :max="999"
              controls-position="right"
            />
          </el-form-item>
          <!-- 状态  0：禁用 ，1： 可用 -->
          <!-- 状态值 -->
          <el-form-item label="状态" prop="status">
            <!-- 代码生成器生成的 默认从通用字典 common_status 里取值，其他情况，请手动修改-->
            <el-radio-group v-for="s in dict.common_status" :key="s.key" v-model="form.status">
              <el-radio :label="Number(s.key)">{{ s.value }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>

        <div class="leisure-drawer__footer">
          <el-button
            @click="crud.cancelCU"
          >
            取消
          </el-button>
          <el-button
            :loading="crud.status.cu === 2"
            type="primary"
            @click="crud.submitCU"
          >
            确认
          </el-button>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import CRUD, { form } from '@crud/crud'
import DepTree from '@/views/components/depTree'
// 岗位 - model
const defaultForm = {
  id: null, // id
  name: null, // 岗位名称
  code: null, // 岗位编码
  topid: null, // 限定组织的顶级id
  depId: null, // 组织id
  paixu: 1,
  status: 1,
  lockVersion: 0,
  createUser: null
}
export default {
  components: {
    DepTree
  },
  mixins: [form(defaultForm)],
  dicts: [
    'common_status'
  ], // 字典
  data() {
    return {
      rules: {
        depId: [
          { required: true, message: '请选择所属组织', trigger: 'change' }
        ],
        paixu: [
          { required: true, message: '请输入序号', trigger: 'blur', type: 'number' }
        ]
      }
    }
  },
  mounted() {
  },
  methods: {
    depSearchInput(value) {
      this.form.depId = value
    },
    [CRUD.HOOK.beforeToCU]() {

    }
  }
}
</script>

<style lang="scss" scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }

</style>
